package com.ByteDance.service.impl;

import com.ByteDance.model.po.VideoEntity;
import com.ByteDance.service.IVideoService;
import com.ByteDance.service.Strategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
@RequiredArgsConstructor
public class GetLatestStrategyImpl implements Strategy {

    private final IVideoService videoService;

    @Value("${video-config.feed-video-max-num}")
    private String VIDEO_MAX_NUM;

    @Override
    public List<VideoEntity> getVideo(Timestamp timestamp) {
        LambdaQueryWrapper<VideoEntity> lambdaQuery = new LambdaQueryWrapper<>();
                lambdaQuery.le(VideoEntity::getPublishTime, timestamp).orderByDesc(VideoEntity::getPublishTime)
                        .last("limit " + VIDEO_MAX_NUM);
        return videoService.list(lambdaQuery);
    }
}
